
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 01/27/2018 09:34:34
-- Generated from EDMX file: F:\Projects\Learning\src\Zj.DotNetCore\src\Zj.HttpCodeDemo\Zj.HttpCodeDemo.ConsoleApp\ModelFirst\ModelFirstTest.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [ModelFirstTest];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'User'
CREATE TABLE [dbo].[User] (
    [Id] bigint IDENTITY(1,1) NOT NULL,
    [UserName] varchar(16)  NOT NULL,
    [Password] varchar(32)  NOT NULL,
    [Age] smallint  NOT NULL
);
GO

-- Creating table 'UserLoginErrLog'
CREATE TABLE [dbo].[UserLoginErrLog] (
    [Id] bigint IDENTITY(1,1) NOT NULL,
    [IPAddress] varchar(64)  NOT NULL,
    [LoginTime] datetime  NOT NULL,
    [UserId] bigint  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'User'
ALTER TABLE [dbo].[User]
ADD CONSTRAINT [PK_User]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserLoginErrLog'
ALTER TABLE [dbo].[UserLoginErrLog]
ADD CONSTRAINT [PK_UserLoginErrLog]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [UserId] in table 'UserLoginErrLog'
ALTER TABLE [dbo].[UserLoginErrLog]
ADD CONSTRAINT [FK_UserUserLoginErrLog]
    FOREIGN KEY ([UserId])
    REFERENCES [dbo].[User]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating non-clustered index for FOREIGN KEY 'FK_UserUserLoginErrLog'
CREATE INDEX [IX_FK_UserUserLoginErrLog]
ON [dbo].[UserLoginErrLog]
    ([UserId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------